package com.y.simple.validator;

import com.y.simple.bean.LoginBean;
import com.y.simple.dto.UserMainQueryDto;
import com.y.simple.entity.User;
import com.y.simple.global.ResultException;
import com.y.simple.utils.StringUtil;

public class UserValidator {

    public static void validator(User user) {
        User.validator(user);
    }

    public static void loginValidator(LoginBean bean) {
        // 用户名、邮箱、手机有且只有一个有值
        int count = 0;
        if (StringUtil.hasEmpty(bean.getUserName())) {
            count ++;
        }
        if (StringUtil.hasEmpty(bean.getUserEmail())) {
            count ++;
        }
        if (StringUtil.hasEmpty(bean.getUserPhone())) {
            count ++;
        }
        if (count != 1) {
            throw new ResultException("400","参数非法");
        }
        // 密码不能为空
        if (!StringUtil.hasEmpty(bean.getUserPassword())) {
            throw new ResultException("400","密码不能为空");
        }
        // 类型值需有
        if (!StringUtil.hasEmpty(bean.getUserType())) {
            throw new ResultException("400","无法识别的用户类型");
        }

    }


}
